#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std;
int p = 10007, n;
int z[120][120];
int pw(int x, int y) {
	int re = 1;
	for (; y > 0; y >>= 1) {
		if (y & 1) {
			re = (long long)re * x % p;
		}
		x = (long long)x * x % p;
	}
	return re;
}

int det() {
	int re = 1;
	for (int i = 0; i < n - 1; i++) {
		int t = -1;
		for (int j = i; j < n - 1; j++) {
			if (z[i][j] != 0) {
				t = j;
				break;
			}
		}
		if (t == -1) {
			return 0;
		}
		if (t != i) {
			for (int j = 0; j < n - 1; j++) {
				swap(z[t][j], z[i][j]);
			}
			re = -re;			
		}
		for (int j = i + 1; j < n - 1; j++) {
			int u = (long long)pw(z[i][i], p - 2) * z[j][i] % p;
			for (int k = 0; k < n - 1; k++) {
				z[j][k] = (z[j][k] + p - ((long long)u * z[i][k]) % p) % p;
			}
		}
		re = (long long)re * z[i][i] % p;
	}
	return re;
}


int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			int x;
			scanf("%d", &x);
			z[i][j] -= x;
			z[i][i] += x;
		}
	}

	for (int i = 0; i < n - 1; i++) {
		for (int j = 0; j < n - 1; j++) {
			z[i][j] = z[i + 1][j + 1];
		}
	}
	printf("%d\n", det());
	return 0;
}